<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Banner</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiAdmin.std/src/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiAdmin.std/src/layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-form">
                        <input type="hidden" id="id" name="id" value="{$entry.id}" />
                        <div class="layui-form-item">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" id="title" name="title" value="{$entry.title}"
                                       lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">分组：</label>
                            <div class="layui-input-block">
                                <input type="text" id="grp" name="grp" value="{$entry.grp}"
                                       lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">图片：</label>
                            <div class="layui-input-inline">
                                <input type="text" id="pic" name="pic" value="{$entry.pic}"
                                       lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                                <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">
                                    <i class="layui-icon">&#xe67c;</i>上传图片
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="view_avatar()">查看图片</button>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">跳转地址：</label>
                            <div class="layui-input-block">
                                <input type="text" id="jump_url" name="jump_url" value="{$entry.jump_url}"
                                       lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">排序值：</label>
                            <div class="layui-input-block">
                                <input type="text" id="idx" name="idx" value="{$entry.idx}"
                                       lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit lay-filter="btn_save" id="btn_save">保存编辑</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/static/layuiAdmin.std/src/layuiadmin/layui/layui.js"></script>
<script>
    var tree;
    var layer;
    var util;
    var select;
    var $;
    var form;
    var layedit;
    var upload;

    function view_avatar() {
        var src = $('#pic').val();
        layer.photos({
            photos: {
                "title": "查看图片" //相册标题
                ,"data": [{
                    "src": src //原图地址
                }]
            }
            ,shade: 0.01
            ,closeBtn: 1
            ,anim: 5
        });
    }

    function save(field) {
        $('#btn_save').hide()
        $.ajax({
            url: 'save',
            type: 'POST',
            data: field,
            dataType: 'json',
            success: function (data) {
                if (data.code == '0') {
                    layer.msg('保存成功', { icon: 1, time: 2000 }, function () {
                        parent.layer.closeAll()
                        parent.$('#btnSearch').click();
                        $('#btn_save').show()
                    });
                } else {
                    layer.msg(data.msg, { icon: 5, time: 2000 });
                    $('#btn_save').show()
                }
            }
        });
    }

    layui.config({
        base: '/static/layuiAdmin.std/src/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'tree', 'util', 'customSelect', 'layedit', 'upload'], function(){
        tree = layui.tree
        layer = layui.layer
        util = layui.util
        select = layui.customSelect
        $ = layui.$
        form = layui.form
        layedit = layui.layedit;
        upload = layui.upload

        //上传图片
        upload.render({
            url: '/admin/common/upload_pic'
            ,elem: '#LAY_avatarUpload'
            ,done: function(res){
                if(res.code == 0){
                    $('#pic').val(res.data.url);
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });

        form.on('submit(btn_save)', function(obj){
            save(obj.field)
        });
    });
</script>
</body>
</html>
